﻿<html>

	<head>
		<title>用户导入</title>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">

		<link href="../../css/skin/default/style.css" rel="stylesheet" type="text/css" />
		<link href="../../css/dialog.css" rel="stylesheet">
		<link href="../../js/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />

		<script src="../../js/lib/jquery/jquery-1.10.2.min.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>

		<script src="../../js/lib/ligerUI/js/plugins/ligerPopupEdit.js"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerCheckBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDateEditor.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerRadio.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerMenu.js" type="text/javascript"></script>
		<script type="text/javascript" src="../../js/JS/plupload/js/plupload.full.min.js"></script>
		<script src="../../js/lib/jquery.form.js" type="text/javascript"></script>
		<script src="../../js/lib/json2.js" type="text/javascript"></script>
		<script src="../../js/dialog.js"></script>
		<script src="../../js/JS/layout.js"></script>
		<script src="../../js/constants.js" type="text/javascript"></script>
		<script src="../../js/api.js" type="text/javascript"></script>
		

		<style>
			body .l-button {
				width: 60px;
				float: left;
			}
		</style>
		<script type="text/javascript">
			var manager;
			$(document).hover(parent.hindMenu);
			$(function() {
				$("form").ligerForm();
				initMember();
				var url=BaseUrl+"SpUser?token="+$api.getStorage("token");
				var uploader = new plupload.Uploader({
					browse_button: 'pickfiles', // you can pass in id...
					url: url,
					chunk_size: '1mb',
					unique_names: true,
					filters: {
						max_file_size: '10mb',
						mime_types: [{
							title: "execl文件",
							extensions: "xls,xlsx"
						}],
						prevent_duplicates: true //可重选 
					},
					multi_selection: false, //不可多选
					flash_swf_url: '../../js/JS/plupload/js/Moxie.swf',
					silverlight_xap_url: '../../js/JS/plupload/js/Moxie.xap', 
					preinit: {
						Init: function(up, info) {
							console.log('[Init]' + 'Info:' + info + 'Features:' + up.features);
						},
						UploadFile: function(up, file) {}
					},
					init: {
						PostInit: function() {

							document.getElementById('import').onclick = function() {
								if($api.isEmpty($("#FuExecl").val())) {
									top.$.ligerDialog.error("请先选择文件！");
									return false;
								}
								top.$.ligerDialog.waitting('正在导入数据,请稍候...');
								uploader.start();
								return false;
							}
						},

						Browse: function(up) {
							// Called when file picker is clicked
							//log('[Browse]');

						},
						Refresh: function(up) {
							// Called when the position or dimensions of the picker change
							//log('[Refresh]');
						},
						StateChanged: function(up) {
							// Called when the state of the queue is changed
							// log('[StateChanged]', up.state == plupload.STARTED ? "STARTED" : "STOPPED");
						},
						QueueChanged: function(up) {
							// Called when queue is changed by adding or removing files
							//  log('[QueueChanged]');
						},

						OptionChanged: function(up, name, value, oldValue) {
							// Called when one of the configuration options is changed
							// log('[OptionChanged]', 'Option Name: ', name, 'Value: ', value, 'Old Value: ', oldValue);
						},

						BeforeUpload: function(up, file) {
							// Called right before the upload for a given file starts, can be used to cancel it if required
							// log('[BeforeUpload]', 'File: ', file);
						},
						UploadProgress: function(up, file) {
							// Called while file is being uploaded
							//log('[UploadProgress]', 'File:', file, "Total:", up.total);
						},

						FileFiltered: function(up, file) {
							// Called when file successfully files all the filters
							// log('[FileFiltered]', 'File:', file);
						},
						FilesAdded: function(up, files) {
							// Called when files are added to queue
							//  log('[FilesAdded]');
							plupload.each(files, function(file) {
								$("#FuExecl").val(file.name);
								//   log('  File:', file);
							});
						},
						FilesRemoved: function(up, files) {
							// Called when files are removed from queue
							//log('[FilesRemoved]');
							plupload.each(files, function(file) {
								//  log('  File:', file);
							});
						},
						FileUploaded: function(up, file, result) {
							top.$.ligerDialog.closeWaitting();
							$("#FuExecl").val("");
							if(result.status) {
							    var objs = JSON.parse(result.response);
								if(objs.Code==0) {
									if(Number(objs.Message)>0)
										top.$.ligerDialog.success("成功导入=="+objs.Message);
									for(var i in objs.Rows) {
										var obj = objs.Rows[i];
										manager.addRow(obj);
									}
								} else {
									top.$.ligerDialog.error(objs.Message);
								}
							}
						},
						ChunkUploaded: function(up, file, info) {
							// Called when file chunk has finished uploading
							//   log('[ChunkUploaded] File:', file, "Info:", info);
						},

						UploadComplete: function(up, files) {

							// Called when all files are either uploaded or failed
							//  log('[UploadComplete]');
						},

						Destroy: function(up) {
							// Called when uploader is destroyed
							//log('[Destroy] ');
						},
						Error: function(up, args) {
							// Called when error occurs
							top.$.ligerDialog.closeWaitting();
							top.$.ligerDialog.error("请修改文件名后再试！");
						}
					}
				});
				uploader.init();
			});

			//导入
			function importdata() {

				var filename;
				var location;
				filename = $("#FuExecl").val();
				location = "file:///" + $("#FuExecl").val();
				var type = location.substr(location.lastIndexOf(".")).toLowerCase();
				if(type == ".xls" || type == ".xlsx") {
					manager.reload();
					ajaxFileUpload(filename);
				} else {
					$.ligerDialog.error("上传文件格式错误！");
				}
			}

			var url = "";

			function initMember() {
				manager = $("#maingrid").ligerGrid({
					rownumbers: true,
					checkbox: false,
					rowHeight:33,
					dataAction: 'local',
					url: url,
					width: '100%',
					height: '90%', 
					columns: [{
							display: '行号',
							name: 'Frow',
							width: 120,
							align: 'left'
						},{
							display: '会员',
							name: 'Mobile',
							width: 120,
							align: 'left'
						},
						{
							display: '姓名',
							name: 'Name', 
							width: 180
						},						 
						{
							display: '错误信息',
							name: 'Error',
							minwidth: 220,
							align: 'left'
						}

					],
					usePager: false,
					allowHideColumn: false
				});

			}
		</script>

	</head>

	<body class="mainbody">
		<form id="form2" >

			<div class="location" width="300px">

				<table style="font-size: 12px;" >
					<tr>
						<td  >
							<span style="margin-left:10px">会员管理</span>
							<i class="arrow"></i>
							<span class="nows">数据导入</span> </td>
					</tr>
				</table>
			</div>

			<div class="line10"></div>
			<div>
				<table style="font-size: 12px;width: 100%;" class='bodytable2'>

					<tr>
						<td width="72px" align="center">
							<a style="cursor:pointer;color:blue;" download="" href="../../attach/会员导入模板.xlsx">模板下载 </a>

						</td>
						<td width="72px"  align="left">
							 
								文件选择： 
						</td>
						<td>
							<div style="float: left;">
								<input ltype="text" type="text" id="FuExecl" name="FuExecl" style="width:182px;height:27px;" />
							</div>
							<div style="float: left;margin-left: 5px;margin-top: 10px;">
								<a id="pickfiles" href="javascript:;">选择文件</a>
							</div>
						</td>

						<td>
							<a class="btn green" id="import">导入</a>
						</td>

						<td width="40%">
						</td>

					</tr>

				</table>

				<div id="maingrid" style="margin: 5px 0 0 0 ;"></div>
				<div class="div-content" style="margin-top: 10px;width:99.5%">
					<div class="divhead">信息管理小贴士</div>
					<hr class="divline" />
					<div style="padding:1px 5px; line-height:22px;"><span style="font-weight:bold">导入：</span>根据匹配情况，已经在库的用户将不在导入。</div>
					<div style="padding:1px 5px; line-height:22px;"><span style="font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>会员导入后将不能删除；
					</div>

				</div>
			</div>

		</form>

	</body>

</html>